<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Demo-17-生命周期</title>
    <script type="text/javascript" src="../JS/vue.js"></script>
</head>
<body>
<div id="root">
    <h3>当前的 n 值为 {{ n }} </h3>
    <button @click="add()">点我 n 加一</button>
    <button @click="bye()">点我销毁 vm</button>
</div>

<script text="text/javascript">
    const vm = new Vue({
        el: '#root',

        data: {
            n: 1,
        },

        methods: {
            add() {
                this.n++
            },

            bye() {
                console.log('bye')
                this.$destroy()
            }
        },

        beforeCreate() {
            console.log('beforeCreate')
        },

        create() {
            console.log('create')
        },

        beforeMount() {
            console.log('beforeMount')
        },

        mounted() {
            console.log('mounted')
        },

        beforeUpdate() {
            console.log('beforeUpdate')
        },

        updated() {
            console.log('update')
        },

        beforeDestroy() {
            console.log('beforeDestroy')
        },

        destroyed() {
            console.log('destroyed')
        },
    })

</script>
</body>
</html>